package public

import (
	"context"
	"encoding/json"
	"fmt"

	"server/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type TestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestLogic {
	return &TestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *TestLogic) Test() (resp []map[string]any, err error) {
	jsonStr := `
	[
        {
            "path": "/system",
            "component": "Layout",
            "redirect": "/system/user",
            "name": "/system",
            "meta": {
                "title": "系统管理",
                "icon": "system",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "user",
                    "component": "system/user/index",
                    "name": "User",
                    "meta": {
                        "title": "用户管理",
                        "icon": "el-icon-User",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "role",
                    "component": "system/role/index",
                    "name": "Role",
                    "meta": {
                        "title": "角色管理",
                        "icon": "role",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "menu",
                    "component": "system/menu/index",
                    "name": "SysMenu",
                    "meta": {
                        "title": "菜单管理",
                        "icon": "menu",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "dept",
                    "component": "system/dept/index",
                    "name": "Dept",
                    "meta": {
                        "title": "部门管理",
                        "icon": "tree",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "dict",
                    "component": "system/dict/index",
                    "name": "Dict",
                    "meta": {
                        "title": "字典管理",
                        "icon": "dict",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "log",
                    "component": "system/log/index",
                    "name": "Log",
                    "meta": {
                        "title": "系统日志",
                        "icon": "document",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "dict-item",
                    "component": "system/dict/dict-item",
                    "name": "DictItem",
                    "meta": {
                        "title": "字典数据",
                        "icon": "",
                        "hidden": true,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "config",
                    "component": "system/config/index",
                    "name": "Config",
                    "meta": {
                        "title": "系统配置",
                        "icon": "setting",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "notice",
                    "component": "system/notice/index",
                    "name": "Notice",
                    "meta": {
                        "title": "通知公告",
                        "icon": "",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        },
        {
            "path": "/codegen",
            "component": "Layout",
            "name": "/codegen",
            "meta": {
                "title": "系统工具",
                "icon": "menu",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "codegen",
                    "component": "codegen/index",
                    "name": "Codegen",
                    "meta": {
                        "title": "代码生成",
                        "icon": "code",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        },
        {
            "path": "/api",
            "component": "Layout",
            "redirect": "/api/apifox",
            "name": "/api",
            "meta": {
                "title": "接口文档",
                "icon": "api",
                "hidden": false,
                "alwaysShow": true,
                "params": null
            },
            "children": [
                {
                    "path": "apifox",
                    "component": "demo/api/apifox",
                    "name": "Apifox",
                    "meta": {
                        "title": "Apifox",
                        "icon": "api",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        },
        {
            "path": "/doc",
            "component": "Layout",
            "redirect": "https://juejin.cn/post/7228990409909108793",
            "name": "/doc",
            "meta": {
                "title": "平台文档",
                "icon": "document",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "internal-doc",
                    "component": "demo/internal-doc",
                    "name": "InternalDoc",
                    "meta": {
                        "title": "document",
                        "icon": "document",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "https://juejin.cn/post/7228990409909108793",
                    "name": "Https://juejin.cn/post/7228990409909108793",
                    "meta": {
                        "title": "项目文档(外链)",
                        "icon": "document",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "https://youlai.blog.csdn.net/article/details/145178880",
                    "name": "Https://youlai.blog.csdn.net/article/details/145178880",
                    "meta": {
                        "title": "后端文档",
                        "icon": "document",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "https://youlai.blog.csdn.net/article/details/143222890",
                    "name": "Https://youlai.blog.csdn.net/article/details/143222890",
                    "meta": {
                        "title": "移动端文档",
                        "icon": "document",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        },
        {
            "path": "/multi-level",
            "component": "Layout",
            "redirect": "/multi-level/multi-level1/multi-level2/multi-level3-1",
            "name": "/multiLevel",
            "meta": {
                "title": "多级菜单",
                "icon": "cascader",
                "hidden": false,
                "alwaysShow": true,
                "params": null
            },
            "children": [
                {
                    "path": "multi-level1",
                    "component": "demo/multi-level/level1",
                    "redirect": "/multi-level/multi-level1/multi-level2/multi-level3-1",
                    "name": "MultiLevel1",
                    "meta": {
                        "title": "菜单一级",
                        "icon": "",
                        "hidden": false,
                        "alwaysShow": true,
                        "params": null
                    },
                    "children": [
                        {
                            "path": "multi-level2",
                            "component": "demo/multi-level/children/level2",
                            "redirect": "/multi-level/multi-level1/multi-level2/multi-level3-1",
                            "name": "MultiLevel2",
                            "meta": {
                                "title": "菜单二级",
                                "icon": "",
                                "hidden": false,
                                "alwaysShow": false,
                                "params": null
                            },
                            "children": [
                                {
                                    "path": "multi-level3-1",
                                    "component": "demo/multi-level/children/children/level3-1",
                                    "name": "MultiLevel31",
                                    "meta": {
                                        "title": "菜单三级-1",
                                        "icon": "",
                                        "hidden": false,
                                        "keepAlive": true,
                                        "alwaysShow": false,
                                        "params": null
                                    }
                                },
                                {
                                    "path": "multi-level3-2",
                                    "component": "demo/multi-level/children/children/level3-2",
                                    "name": "MultiLevel32",
                                    "meta": {
                                        "title": "菜单三级-2",
                                        "icon": "",
                                        "hidden": false,
                                        "keepAlive": true,
                                        "alwaysShow": false,
                                        "params": null
                                    }
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "path": "/component",
            "component": "Layout",
            "name": "/component",
            "meta": {
                "title": "组件封装",
                "icon": "menu",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "curd",
                    "component": "demo/curd/index",
                    "name": "Curd",
                    "meta": {
                        "title": "增删改查",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "table-select",
                    "component": "demo/table-select/index",
                    "name": "TableSelect",
                    "meta": {
                        "title": "列表选择器",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "wang-editor",
                    "component": "demo/wang-editor",
                    "name": "WangEditor",
                    "meta": {
                        "title": "富文本编辑器",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "upload",
                    "component": "demo/upload",
                    "name": "Upload",
                    "meta": {
                        "title": "图片上传",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "dict-demo",
                    "component": "demo/dictionary",
                    "name": "DictDemo",
                    "meta": {
                        "title": "字典组件",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "icon-selector",
                    "component": "demo/icon-selector",
                    "name": "IconSelector",
                    "meta": {
                        "title": "图标选择器",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "drag",
                    "component": "demo/drag",
                    "name": "Drag",
                    "meta": {
                        "title": "拖拽组件",
                        "icon": "",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "text-scroll",
                    "component": "demo/text-scroll",
                    "name": "TextScroll",
                    "meta": {
                        "title": "滚动文本",
                        "icon": "",
                        "hidden": false,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        },
        {
            "path": "/route-param",
            "component": "Layout",
            "name": "/routeParam",
            "meta": {
                "title": "路由参数",
                "icon": "el-icon-ElementPlus",
                "hidden": false,
                "alwaysShow": true,
                "params": null
            },
            "children": [
                {
                    "path": "route-param-type1",
                    "component": "demo/route-param",
                    "name": "RouteParamType1",
                    "meta": {
                        "title": "参数(type=1)",
                        "icon": "el-icon-Star",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": {
                            "type": "1"
                        }
                    }
                },
                {
                    "path": "route-param-type2",
                    "component": "demo/route-param",
                    "name": "RouteParamType2",
                    "meta": {
                        "title": "参数(type=2)",
                        "icon": "el-icon-StarFilled",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": {
                            "type": "2"
                        }
                    }
                }
            ]
        },
        {
            "path": "/function",
            "component": "Layout",
            "name": "/function",
            "meta": {
                "title": "功能演示",
                "icon": "menu",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "icon-demo",
                    "component": "demo/icons",
                    "name": "IconDemo",
                    "meta": {
                        "title": "Icons",
                        "icon": "el-icon-Notification",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "/function/websocket",
                    "component": "demo/websocket",
                    "name": "/function/websocket",
                    "meta": {
                        "title": "Websocket",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "/function/dict-sync",
                    "component": "demo/dict-sync",
                    "name": "/function/dictSync",
                    "meta": {
                        "title": "字典实时同步",
                        "icon": "",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        }
    ]
	`

	jsonStr = `
	[
        {
            "path": "/system",
            "component": "Layout",
            "redirect": "/system/user",
            "name": "/system",
            "meta": {
                "title": "系统管理",
                "icon": "system",
                "hidden": false,
                "alwaysShow": false,
                "params": null
            },
            "children": [
                {
                    "path": "user",
                    "component": "system/user/index",
                    "name": "User",
                    "meta": {
                        "title": "用户管理",
                        "icon": "el-icon-User",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "role",
                    "component": "system/role/index",
                    "name": "Role",
                    "meta": {
                        "title": "角色管理",
                        "icon": "role",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                },
                {
                    "path": "menu",
                    "component": "system/menu/index",
                    "name": "SysMenu",
                    "meta": {
                        "title": "菜单管理",
                        "icon": "menu",
                        "hidden": false,
                        "keepAlive": true,
                        "alwaysShow": false,
                        "params": null
                    }
                }
            ]
        }
    ]
	`

	// jsonStr = `
	// [
	//     {
	//         "name": "/system",
	//         "path": "/system",
	//         "redirect": "/system/user",
	//         "component": "Layout",
	//         "meta": {
	//             "alwaysShow": false,
	//             "hidden": false,
	//             "icon": "system",
	//             "params": null,
	//             "title": "系统管理"
	//         },
	//         "children": [
	//             {
	//                 "name": "User",
	//                 "path": "user",
	//                 "redirect": "",
	//                 "component": "system/user/index",
	//                 "meta": {
	//                     "alwaysShow": true,
	//                     "hidden": false,
	//                     "icon": "el-icon-User",
	//                     "keepAlive": false,
	//                     "params": null,
	//                     "title": "用户管理"
	//                 }
	//             },
	//             {
	//                 "name": "Role",
	//                 "path": "role",
	//                 "redirect": "",
	//                 "component": "system/role/index",
	//                 "meta": {
	//                     "alwaysShow": true,
	//                     "hidden": false,
	//                     "icon": "role",
	//                     "keepAlive": false,
	//                     "params": null,
	//                     "title": "角色管理"
	//                 }
	//             },
	//             {
	//                 "name": "Permisson",
	//                 "path": "permisson",
	//                 "redirect": "",
	//                 "component": "system/permisson/index",
	//                 "meta": {
	//                     "alwaysShow": true,
	//                     "hidden": false,
	//                     "icon": "menu",
	//                     "keepAlive": false,
	//                     "params": null,
	//                     "title": "权限管理"
	//                 }
	//             }
	//         ]
	//     }
	// ]
	// `

	jsonStr = `
	[
  {
    "path": "/system",
    "component": "Layout",
    "redirect": "/system/user",
    "name": "/system",
    "meta": {
      "title": "系统管理",
      "icon": "system",
      "hidden": false,
      "alwaysShow": false,
      "params": null
    },
    "children": [
      {
        "name": "User",
        "path": "user",
        "redirect": "",
        "component": "system/user/index",
        "meta": {
          "alwaysShow": true,
          "hidden": false,
          "icon": "el-icon-User",
          "keepAlive": false,
          "params": null,
          "title": "用户管理"
        }
      },
      {
        "name": "Role",
        "path": "role",
        "redirect": "",
        "component": "system/role/index",
        "meta": {
          "alwaysShow": true,
          "hidden": false,
          "icon": "role",
          "keepAlive": false,
          "params": null,
          "title": "角色管理"
        }
      },
      {
        "name": "Permisson",
        "path": "permisson",
        "redirect": "",
        "component": "system/permisson/index",
        "meta": {
          "alwaysShow": true,
          "hidden": false,
          "icon": "menu",
          "keepAlive": false,
          "params": null,
          "title": "权限管理"
        }
      }
    ]
  }
]
	`
	result := []map[string]any{}
	err = json.Unmarshal([]byte(jsonStr), &result)
	if err != nil {
		fmt.Println("Error:", err)
		return
	}
	return result, nil
}
